<template>
	<!-- 跳转页面 -->
	<view class="auditor">
		<navBar :titleText="titleText"></navBar>
		<view class="auditor-mian">
			<none v-if="sudioList.length==0&&!hasMore"></none>
			<view v-else class="auditorList" v-for="(item,index) in sudioList" :key="index">
				<view class="avatarImg">
					<image :src="item.avatar" mode=""></image>
				</view>
				<view class="userinfo">
					<view class="userinfo-title">{{item.name}} {{item.sex=='1'?"男":"女"}} {{item.telphone}}</view>
					<view class="userinfo-address">{{item.province}}{{item.city}}{{item.county}}</view>
				</view>
				<view class="userinfo-type refuse" v-if="titleText.includes('申请')" @tap="refuse(item)">拒绝</view>
				<view class="userinfo-type" @tap="pushButton(item)" :class="item.audiotorType=='冻结'||item.audiotorType=='删除'?'redback':'greenback'">{{item.audiotorType}}</view>
			</view>
			<noMore v-if="!hasMore"></noMore>
			<view v-else class="loading">加载中...</view>
		</view>
		<!-- 充值弹框 -->
		<popup v-if="showRecharge" openRouter="rechange" :popData="popData" @changeData="hidePop"> </popup>
	</view>
</template>

<script>
	import navBar from "@/component/count/navBar.vue"
	import util from '@/component/commen/api/util.js';
	import none from "@/otherPages/none/none.vue"
	import noMore from "@/component/noMore.vue"
	import popup from "@/component/popup.vue"//引入弹框
	export default {
		components:{navBar,none,popup,noMore},
		data() {
			return {
				titleText:"",//navbar标题
				sudioList:[],//列表数据
				showRecharge:false,//是否显示充值弹框
				popData:{},//充值选择的值
				page:1,//页
				psize:10,//每页条数
				hasMore:true,//是否还有更多数据
			};
		},
		onLoad(e) {
			this.titleText = e.title
			console.log("标题",this.titleText)
		},
		onShow() {
			// console.log("标题",this.titleText)
			this.getauditorDetail()
		},
		onReachBottom() {
			this.page++
			this.getauditorDetail()
			console.log("触底加载")
		},
		methods:{
			pushButton(value){//点击按钮
				var that = this
				if(this.titleText.includes("充值")){
					this.showRecharge = true
					this.popData = value
					// 1:回收员充值；2:合伙人充值
					this.popData.type = this.titleText=="回收员充值"?'1':'2'
					console.log(this.popData)
				}else if(this.titleText.includes("冻结")){
					uni.showModal({
						title:"确定要冻结吗?",
						success(event) {
							console.log(event)
							if(event.confirm){
								that.popData.type = that.titleText=="冻结回收员"?'1':'2'
								var parmas = {
									do:"admin",
									op:"freeze",
									type:that.popData.type,
									id:value.id
								}
								util.requestWithSign(parmas).then(res=>{
									console.log(res)
									if(res.errno==0){
										uni.showModal({
											title:"冻结成功！",
											showCancel:false,
											success() {
												that.getauditorDetail()
											}
										})
									}
								})
							}else{
								console.log("取消")
							}
						}
					})
				}else if(this.titleText.includes("解冻")){
					uni.showModal({
						title:"确定要解冻吗？",
						success(event) {
							if(event.confirm){
								that.popData.type = that.titleText=="解冻回收员"?'1':'2'
								var parmas = {
									do:"admin",
									op:"unfreeze",
									type:that.popData.type,
									id:value.id
								}
								util.requestWithSign(parmas).then(res=>{
									console.log(res)
									if(res.errno==0){
										uni.showModal({
											title:"解冻成功！",
											showCancel:false,
											success() {
												that.getauditorDetail()
											}
										})
									}
								})
							}
						}
					})
				}else if(this.titleText.includes("删除")){
					uni.showModal({
						title:"确定要删除吗?",
						success(event) {
							if(event.confirm){
								that.popData.type = that.titleText=="删除回收员"?'1':'2'
								var parmas = {
									do:"admin",
									op:"delete",
									type:that.popData.type,
									id:value.id
								}
								util.requestWithSign(parmas).then(res=>{
									if(res.errno==0){
										uni.showModal({
											title:"删除成功！",
											showCancel:false,
											success() {
												that.getauditorDetail()
											}
										})
									}
								})
							}
						}
					})
				}else if(this.titleText.includes("申请")){//同意申请
					uni.showModal({
						title:"确认同意吗？",
						success(event) {
							if(event.confirm){
								that.popData.type = that.titleText.includes("回收员")?'1':'2'
								var parmas = {
									do:"admin",
									op:"check",
									type:that.popData.type,
									id:value.id
								}
								util.requestWithSign(parmas).then(res=>{
									if(res.errno==0){
										uni.showModal({
											title:"通过成功！",
											showCancel:false,
											success(){
												that.getauditorDetail()
											}
										})
									}
								})
							}
						}
					})
				}
			},
			hidePop(e){
				console.log(e)
				this.showRecharge = e
			},
			refuse(value){//点击拒绝
				var _this = this
				uni.showModal({
					title:"确认拒绝吗?",
					success(event) {
						if(event.confirm){
							_this.popData.type = _this.titleText.includes("回收员")?'1':'2'
							var params = {
								do:"admin",
								op:"refuse",
								type:_this.popData.type,
								id:value.id
							}
							util.requestWithSign(params).then(res=>{
								if(res.errno==0){
									uni.showModal({
										title:"拒绝成功！",
										showCancel:false,
										success() {
											_this.getauditorDetail()
										}
									})
								}
							})
						}
					}
				})
			},
			getauditorDetail(){//获取数据
				if(!this.hasMore){
					return;
				}
				console.log(this.titleText.includes("回收员"))
				let isfreeze = 1
				console.log(this.titleText.includes("申请"))
				if(this.titleText.includes("回收员")&&!this.titleText.includes("申请")){
					console.log("执行啦")
					console.log(this.titleText)
					if(this.titleText.includes("解冻")){
						console.log("解冻")
						isfreeze = 2
						var params = {
						    do:"admin",
						    op:"collectorList",
							freeze_status:isfreeze,
							page: this.page,
							psize: this.psize
						}
						util.requestWithSign(params).then(res=>{
							if(res.errno!=0){
								return uni.showToast({
									title:res.message,
									icon:"none"
								})
							}
							this.sudioList = this.sudioList.concat(res.data.list) 
							this.sudioList.forEach(item=>{
								item.audiotorType = "解冻"
							})
							if(this.sudioList.length==res.data.total){
								return this.hasMore = false
							}
						})
					}else{
						console.log("不是解冻")
						var params = {
						    do:"admin",
						    op:"collectorList",
							freeze_status:isfreeze,
							page:this.page,
							psize:this.psize
						}
						util.requestWithSign(params).then(res=>{
							if(res.errno!=0){
								return uni.showToast({
									title:res.message,
									icon:"none"
								})
							}
							this.sudioList = this.sudioList.concat(res.data.list)
							console.log("111",res)
							// console.log(this.sudioList.length)
							// console.log(res.data.total)
							if(this.titleText.includes("充值")){
								this.sudioList.forEach(item=>{
									item.audiotorType = "充值"
								})
							}else if(this.titleText.includes("冻结")){
								this.sudioList.forEach(item=>{
									item.audiotorType = "冻结"
								})
							}else if(this.titleText.includes("删除")){
								this.sudioList.forEach(item=>{
									item.audiotorType = "删除"
								})
							}
							if(this.sudioList.length==res.data.total){
								return this.hasMore = false
							}
						})
					}
				}else if(!this.titleText.includes("申请")){
					if(this.titleText.includes("解冻")){
						console.log("合伙人解冻")
						isfreeze = 2
						var params = {
						    do:"admin",
						    op:"partnerList",
							freeze_status:isfreeze,
							page:this.page,
							psize:this.psize
						}
						util.requestWithSign(params).then(res=>{
							if(res.errno!=0){
								return uni.showToast({
									title:res.message,
									icon:"none"
								})
							}
							this.sudioList = this.sudioList.concat(res.data.list)
							// this.sudioList = res.data.list
							this.sudioList.forEach(item=>{
								item.audiotorType = "解冻"
							})
							if(this.sudioList.length==res.data.total){
								return this.hasMore = false
							}
						})
					}else{
						console.log("不是解冻")
						var params = {
						    do:"admin",
						    op:"partnerList",
							freeze_status:isfreeze,
							page:this.page,
							psize:this.psize
						}
						util.requestWithSign(params).then(res=>{
							if(res.errno!=0){
								return uni.showToast({
									title:res.message,
									icon:"none"
								})
							}
							this.sudioList = this.sudioList.concat(res.data.list)
							// this.sudioList = res.data.list
							if(this.titleText.includes("充值")){
								this.sudioList.forEach(item=>{
									item.audiotorType = "充值"
								})
							}else if(this.titleText.includes("冻结")){
								this.sudioList.forEach(item=>{
									item.audiotorType = "冻结"
								})
							}else if(this.titleText.includes("删除")){
								this.sudioList.forEach(item=>{
									item.audiotorType = "删除"
								})
							}
							if(this.sudioList.length==res.data.total){
								return this.hasMore = false
							}
						})
					}
				}
				else if(this.titleText.includes("申请")){
					if(this.titleText.includes("回收员")){
						console.log("回收员申请列表")
						var params = {
						    do:"admin",
						    op:"collectorCheckList",
							page:this.page,
							psize:this.psize
						}
						util.requestWithSign(params).then(res=>{
							console.log(res)
							if(res.errno!=0){
								return uni.showToast({
									title:res.message,
									icon:"none"
								})
							}
							this.sudioList = this.sudioList.concat(res.data.list)
							// this.sudioList = res.data.list
							this.sudioList.forEach(item=>{
								item.audiotorType = "同意"
							})
							if(this.sudioList.length==res.data.total){
								return this.hasMore = false
							}
						})
					}else if(this.titleText.includes("合伙人")){
						var params = {
						    do:"admin",
						    op:"partnerCheckList",
							page:this.page,
							psize:this.psize
						}
						util.requestWithSign(params).then(res=>{
							if(res.errno!=0){
								return uni.showToast({
									title:res.message,
									icon:"none"
								})
							}
							this.sudioList = this.sudioList.concat(res.data.list)
							// this.sudioList = res.data.list
							this.sudioList.forEach(item=>{
								item.audiotorType = "同意"
							})
							if(this.sudioList.length==res.data.total){
								return this.hasMore = false
							}
						})
					}
				}
				console.log(this.sudioList)
			}
		},
	}
</script>

<style lang="scss" scoped>
.auditor{
	.auditor-mian{
		padding: 0 20rpx;
		box-sizing: border-box;
		padding-top: 150rpx;//150:navbar高度
		.auditorList{
			background: #fff;
			padding: 20rpx 30rpx;
			box-sizing: border-box;
			border-radius: 10rpx;
			display: flex;
			margin-top: 20rpx;
			.avatarImg{
				width: 86rpx;
				height: 86rpx;
				margin-right: 20rpx;
				border-radius: 50%;
				background: #009b4d;
				image{
					width:100%;
					height: 100%;
					border-radius: 50%;
				}
			}
			.userinfo{
				.userinfo-title{
					font-size: 31rpx;
					font-weight: bold;
				}
				
			}
			.userinfo-type{
				// padding: 8rpx 10rpx;
				width: 100rpx;
				height: 40rpx;
				text-align: center;
				color: #fff;
				border-radius: 24rpx;
				margin-left: auto;
			}
			.refuse{
				background: #eeeeef;
				color: #f00;
				margin-right: 5rpx;
			}
			.redback{
				background: #ff8a23;
			}
			.greenback{
				background:#009b4d ;
			}
			
		}
	}
}
</style>
